/**
 * 权限相关的数据
 * Created by gcc on 2017/9/29.
 */

import Vue from "vue";
import  { Tooltip } from 'view-design'
// 页码相关
let page = {
  total: 1,
  startIndex: 0,
  stepNumber: 20,
  currentPage: 1
};

//页面状态相关
let status = {
  //查看图片
  modalImage: {
    isShow: false,
    url: ''
  },
};

// 和网络交互相关的参数
let params = {
  //搜索条件
  searchParams:{
    searchMatchType:"2",//0全部 1已分配  2未分配
    keyWord:"",
    startEndDate:[],
    isSearchMatched:true
  }
};

// 页面的数据源
let data = {
  userList: [],
  dateRange: {
    disabledDate (date) {
      return date && date.valueOf() > Date.now();
    },
    shortcuts: [
      {
        text: '清空时间',
        value () {
          return [];
        }
      },
      {
        text: '最近一周',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
          return [start, end];
        }
      },
      {
        text: '最近一个月',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
          return [start, end];
        }
      },
      {
        text: '最近三个月',
        value () {
          const end = new Date();
          const start = new Date();
          start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
          return [start, end];
        }
      }
    ]
  },
};

let tableTitles=function (self) {
  var titles =  [
 {
      type: 'index',
      title: '#',
      width: 60,
      key: 'index',
      align: 'center',
    },
    {
      title: '头像',
      key: 'avatar',
      width: 80,
      align: 'center',
      render: (h, params) => {
        return (
          <div>
            <img src={params.row.avatar} height={50} onClick={()=>{
              status.modalImage.url = params.row.avatar;
              status.modalImage.isShow = true;
            }}></img>
          </div>
        );
      }
    },
    {
      title: '注册用户',
      key: 'userName',
      align: "center",
      render: (h, params) => {
        let username = Vue.prototype.$tiyHideUsername(params.row.fullName);
        return (
          <div>
            <Tooltip content={params.row.fullName} placement="top">
                {username}
            </Tooltip>
          </div>
        );

      }
    },
  {
      title: '匹配条件',
      width: 100,
      key: 'matchTimes',
      align: 'center',
    },
     {
      title: '是否已分配',
      key: 'isMatched',
      width: 200,
      align: 'center',
      render: (h, params) => {
        return (
          <div>
            {params.row.isMatched > 0 ? "已分配" : "未分配"}
          </div>
        );

      }
    } ,
    {
      title: '注册时间',
      width: 160,
      key: 'registertime',
      align: 'center',
      render: (h, params) => {
        return h('div', self.$tiyBJTime(params.row.registertime));
      }
    },
    {
      title: '操作',
      key: 'action',
      // fixed: 'right',
      width: 100,
      align: 'center',
      render: (h, params) => {
        let isMatched = params.row.isMatched > 0 ;
        var title = isMatched?'信息查看':'手动分配';
        var type = "success";
        return (self.$authority(self.tRole.USER_4_201))?(
        <div>
          <i-button type={isMatched?'success':'primary'} size="small" onClick={() => { self.allotUserShow(params.index);}} >{title}</i-button>
        </div>):(<div></div>);
      }
    }
  ]

  return self.$authTableTitles(titles);

  };

export  default  {
  tPage: page,
  tStatus: status,
  tParams: params,
  tData: data,
  tableTitles:tableTitles,
};
